using System;
using System.Collections.Generic;
using System.Text;
using System.Net.NetworkInformation;
using System.Security.Cryptography;

namespace Commerce.GoogleCheckout {


    public class GoogleHelper {
        public static string GetButtonImageUrl() {
            string merchantID = System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleMerchantID"].ToString();
            string googleEnvironment = System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleEnvironment"].ToString();
            string result = "";
            if (googleEnvironment == "Sandbox") {
                result = "http://sandbox.google.com/checkout/buttons/checkout.gif?merchant_id=" + merchantID+"&w=180&h=46&style=white&variant=text&loc=en_US";
            } else {
                result = "http://checkout.google.com/buttons/checkout.gif?merchant_id=" + merchantID + "&w=180&h=46&style=white&variant=text&loc=en_US";
            }
            return result;
        }
    }
    
    public class Crypto {

        public static string GetSixtyFour(string message) {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            return System.Convert.ToBase64String(encoding.GetBytes(message));
        }
        public static string GetCartSignature(string cartXML, string sKey) {
            System.Text.ASCIIEncoding encoding = new
            System.Text.ASCIIEncoding();
            byte[] str = encoding.GetBytes(cartXML);
            byte[] key = encoding.GetBytes(sKey);

            // Set cryptobj = Server.CreateObject("GCrypt.g_crypt.2");
            System.Security.Cryptography.HMACSHA1 cryptobj = new
            System.Security.Cryptography.HMACSHA1(key, true);

            // BASE64-ENCODE (input data as String)
            // - outputs base64 encoded binary string
            //b64str.Text = System.Convert.ToBase64String(str);

            // HMACSHA1(input data as String, secret key as String)
            // - outputs base64 encoded binary string
            string sOut = System.Convert.ToBase64String(cryptobj.ComputeHash(str));

            cryptobj.Clear();
            return sOut;

        }
        public static string DecodeBinary(byte[] bIn) {
            System.Text.ASCIIEncoding encoding = new
            System.Text.ASCIIEncoding();

            return encoding.GetString(bIn);
        }
    }
}

